package com.tiecode.pastejava;

import com.sun.source.tree.BinaryTree;
import com.sun.source.tree.ForLoopTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.util.TreeScanner;

public class JavaForLoopDesugar extends TreeScanner<Void, Void> {
    private String varName;
    private String startValue;
    private String endValue;

    public String getVarName() {
        return varName;
    }

    public String getStartValue() {
        return startValue;
    }

    public String getEndValue() {
        return endValue;
    }

    @Override
    public Void visitForLoop(ForLoopTree node, Void unused) {
        scan(node.getInitializer(), null);
        scan(node.getCondition(), null);
        scan(node.getUpdate(), null);
        return null;
    }

    @Override
    public Void visitVariable(VariableTree node, Void unused) {
        varName = node.getName().toString();
        startValue = node.getInitializer().toString();
        return null;
    }

    @Override
    public Void visitBinary(BinaryTree node, Void unused) {
        endValue = node.getRightOperand().toString();
        return null;
    }
}
